package com.wipz.eoa.iphone.costmanagement;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.toft.core2.ToftException;
import com.toft.core2.dao.SqlUtils;
import com.toft.widgets.workflow.model.CompleteTaskResult;
import com.toft.widgets.workflow.utils.ConstantUtil;
import com.wipz.eoa.iphone.BaseServiceImpl;
import com.wipz.eoa.iphone.businessProcess.BusinessCoreServices;
import com.wipz.eoa.iphone.costmanagent.CostDetailProperties;
import com.wipz.eoa.iphone.costmanagent.TracelProperties;

import companycomminutes.CountryTree;

/**
 * 费用报销列表业务接口实现类
 * @author 张涛
 * @date 2012-3-8
 */
public class CostListServiceImpl extends BaseServiceImpl implements ICostListService {

	@SuppressWarnings("unchecked")
	@Override
	public List queryAll(Map params) {		
		return super.queryList("costList.query", params);
	}

	@Override
	public List queryTreeStoreList(String node,String param) {
		Map<Object,Object> treeStoreMap = new HashMap<Object,Object>();
		String reqparam[]=param.split(",");
		List list=new ArrayList();
		List<Map> maplist=new ArrayList<Map>();
		treeStoreMap.put("type",node);
		treeStoreMap.put("COMMITERCODE", "014");
		treeStoreMap.put("BILLCODE", reqparam[1]);
		treeStoreMap.put("TABLE", CostDetailProperties.returnTableNameBytype(Integer.parseInt(reqparam[0])));
	    if("001".equals(node)){
			maplist=super.queryList("treeTraclList.query", treeStoreMap);
		}else if("002".equals(node)){
			maplist=super.queryList("partyList.query", treeStoreMap);
		}else if("003".equals(node)){
			maplist=super.queryList("otherList.query", treeStoreMap);
		}else if("004".equals(node)){
			maplist=super.queryList("lodgingList.query", treeStoreMap); 
		}else if("005".equals(node)){
			maplist=super.queryList("purchaseList.query", treeStoreMap); 
		}

		for (Map currentMap : maplist){
			TracelProperties ct=new TracelProperties();
			try{
				ct.setId((String)currentMap.get("ID"));
				ct.setDetail_id((String)currentMap.get("DETAIL_ID"));
				ct.setType((String)currentMap.get("TYPE"));
				switch (Integer.parseInt(node)) {
				case 001:
					ct.setFileName(((Timestamp)currentMap.get("COSTDATE")).toString());
					break;
				case 002:
					ct.setFileName(((Timestamp)currentMap.get("PARTY_DATE")).toString());
					break;
				case 003:
					ct.setFileName(((Timestamp)currentMap.get("OTHER_DATE")).toString());
					break;
				case 004:
					ct.setFileName(((Timestamp)currentMap.get("LODGING_DATE")).toString());
					break;
				case 005:
					ct.setFileName(((Timestamp)currentMap.get("PURCHASE_DATE")).toString());
				default:
					break;
				}
				ct.setLeaf(true);
				list.add(ct);
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		return list;
	}
	
	public String getSqlNameByType(int type,int node){
		String sqlname="";
		if(type==001){
			switch (node) {
			case 001:
				sqlname= "";
				break;
			case 002:
				sqlname= "";
				break;
			case 003:
				sqlname= "";
				break;
			case 004:
				sqlname= "";
				break;
			default:
				break;
			}
		}else if(type==002){
			switch (node) {
			case 001:
				sqlname= "";
				break;
			case 002:
				sqlname= "";
				break;
			}
		}else{
			return "";
		}
		return sqlname;
	}
	
	@Override
	public List getDailyList(Map param) {
		return super.queryList("datilycostList.query", param);
	}

}
